package classes
{
	import mx.controls.Alert;
	import mx.core.Application;	
	
	
	public class ProjectProperties
	{
		public var _projectName:String;
		public var _projectAuthor:String;
		public var _projectDescription:String;
		public var _projectAcademicLevel:Array;
		public var _projectKeywords:String;
		
		public var _displayNumbers:Boolean = true;
		public var _displayPreviousButton:Boolean = true;
		public var _displayNextButton:Boolean = true;
		public var _displayHomeButton:Boolean = true;
		public var _displayCopyright:String = "Loughborough University";
		
		
		public var _pages:Array;
		
		
		
		public function ProjectProperties()
		{
			//TODO: implement function
			_pages = new Array();
		}
		
		public function AddBlankPage():int{
			//add a new entry to the array
			var newpage:Page = new Page();
			newpage.height = Application.application.default_height;
			newpage.width = Application.application.default_width;
			_pages.push(newpage);
			
			var returnInt:int = _pages.indexOf(newpage);
			
			//return the array index value
			return returnInt;

		}
		
		public function AddClonePage():int{
			//get an istance of the last page class in the array
		var returnInt:int = 0;
			if (_pages.length>=1){
							
				//set up the variables we need to hold the instances of the classes.
				var ClonePage:Page = new Page();
				var LastPage:Page = _pages[_pages.length-1] as Page;
							
				//set the properties of the new class = to the class we are cloneing
				ClonePage.height = LastPage.height;
				ClonePage.width = LastPage.width;
				
				//now we need to loop through the layers and make clones of them before pushing them on to the array.
				for each (var thislayer:Layer in LastPage.layers){
			
//Alert.show(ObjectUtil.toString(thislayer));
					var newLayer:Layer = new Layer();
					newLayer = thislayer
					
					ClonePage.layers.push(newLayer);
	
				}
//Alert.show(ObjectUtil.toString(ClonePage));
	
				//now we need to push the new page on to the array stack
				_pages.push(ClonePage);
				//return the array index value
				returnInt = _pages.indexOf(_pages[_pages.length-1]);
			}else{
				returnInt = AddBlankPage();
			}
			return returnInt;
		}
		
		
		public function DeletePage():void{
			
		}
		
		public function WriteXML():XML{
			 var projectXML:XML = 
				<project>
					<name> {this._projectName} </name>
					<author> {this._projectAuthor} </author>
					<description> {this._projectDescription} </description>
					<academic_level> {this._projectAcademicLevel} </academic_level>
					<keywords> {this._projectKeywords} </keywords>
					<screen_numbers> {this._displayNumbers} </screen_numbers>
					<previous_button> {this._displayPreviousButton} </previous_button>
					<next_button> {this._displayNextButton} </next_button>
					<home_button> {this._displayHomeButton} </home_button>
					<copyright> {this._displayCopyright} </copyright>
				</project>;
			
			//get the xml for the pages (should contain the layers
		var pagesXML:XML = <pages></pages>;
			for (var page:int = 0; page<_pages.length; page++){
				var page_object:Page = new Page();
				page_object = _pages[page];
				var pageXML:XML = page_object.BuildLayersXML();
				
				//projectXML.appendChild(pageXML);
				pagesXML.appendChild(pageXML);
//Alert.show("page out put " + pageXML.toString());				
				
			}
//Alert.show("Pages out put  " + pagesXML.toString());			
				projectXML.appendChild(pagesXML);
							
				return projectXML;
		}
		
		public function PublicDisplayPages():XML{
			var PagesXML:XML = <pages></pages>;
			
			for (var page:int = 0; page<_pages.length; page++){
		
				var page_object:Page = new Page();
				page_object = _pages[page];
				
				var DisplayLabel:int = page +1;
				
				var pageXML:XML = <page>
									<label>{DisplayLabel.toString()}</label>
									<icon>BulletPage</icon>
									<data>{page.toString()}</data>
								  </page>;

				PagesXML.appendChild(pageXML);
			}
			
			return PagesXML;
		}
		
		
		public function SetPreviousButton(value:Boolean):void{
			this._displayPreviousButton = value;
			
		}
		
		public function SetHomeButton(value:Boolean):void{
			this._displayHomeButton = value;
			
		}
		
		public function SetNextButton(value:Boolean):void{
			this._displayNextButton = value;
			
		}
		
		public function SetdisplayNumbers(value:Boolean):void{
			this._displayNumbers = value;
			
		}
		
		public function SetCopyright(notice:String):void{
			this._displayCopyright = notice;
		}
		
		

		
	}
	
}